<?php

namespace App\Admin\Controllers;

use App\Models\Announcement;
use Carbon\Carbon;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class AnnouncementController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Announcement(), function (Grid $grid) {
            $grid->column('title');
            $grid->column('content');
            $grid->column('publish_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('title');

            });

            $grid->showQuickEditButton();
            $grid->disableViewButton();
            $grid->disableEditButton();
        });
    }


    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Announcement(), function (Form $form) {
            $form->text('title')->required();
            $form->editor('content')->required();
            $form->datetime('publish_at')->default(Carbon::now());

        });
    }
}
